use sqlx::SqlitePool;
use crate::db;
use crate::error::AppResult;
use crate::models::{Chat, CreateChat};

pub struct ChatService;

impl ChatService {
    /// 保存聊天记录
    pub async fn save_chat(pool: &SqlitePool, create_chat: CreateChat) -> AppResult<Chat> {
        db::chat::create(pool, &create_chat).await
    }
    
    /// 获取用户最近的聊天记录
    pub async fn get_recent_chats(pool: &SqlitePool, user_id: i64, limit: i64) -> AppResult<Vec<Chat>> {
        db::chat::find_by_user_id(pool, user_id, limit).await
    }
}
